package _94ZeRenLian;

import _94ZeRenLian.sub.ConsoleLogger;
import _94ZeRenLian.sub.ErrorLogger;
import _94ZeRenLian.sub.FileLogger;

/**
 * @Test: 责任链模式 测试类
 * @author: ZBoHang
 * @time: 2021/9/15 16:57
 */
class Test {
    public static AbstractLogger getChainOfLoggers() {
        AbstractLogger consoleLogger = new ConsoleLogger(AbstractLogger.DEBUG);
        AbstractLogger fileLogger = new FileLogger(AbstractLogger.INFO);
        AbstractLogger errorLogger = new ErrorLogger(AbstractLogger.ERROR);

        consoleLogger.setNextLogger(fileLogger);
        errorLogger.setNextLogger(consoleLogger);
        return errorLogger;
    }

    public static void main(String[] args) {
        AbstractLogger chainOfLoggers = getChainOfLoggers();
        System.out.println("******************************************");

        chainOfLoggers.logMessage(AbstractLogger.INFO, "info消息");
        System.out.println("******************************************");

        chainOfLoggers.logMessage(AbstractLogger.DEBUG, "debug消息");
        System.out.println("******************************************");

        chainOfLoggers.logMessage(AbstractLogger.ERROR, "error消息");
        System.out.println("******************************************");
    }
}
